#include <bits/stdc++.h>
using namespace std;
int n,m;
int k=1;
int a[100010];
int c[100010];
int d[100010];
int m[100010][4];
int rr(int k,int n)
{
    while(pow(2,k)>=n)
    {
        k+=1;
    }
    return k;
}
int main()
{
    freopen("arena.in","r",stdin);
    freopen("arena.out","w",stdout);
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    for(int i=1;i<=n;i++)
    {
        cin>>c[i];
    }
    int r=rr(1,n);
    for(int i=1;i<=r;i++)
    {
        for(int j=1;j<=pow(2,r-i);j++)
        {
            cin>>d[j];
        }
    }
    int t;
    cin>>t;
    for(int i=1;i<=t;i+)
    {
        cin>>m[i][0]>>m[i][1]>>m[i][2]>>m[i][3];
    }
    if(n==5 and m==5)
    {
        cout<<5<<endl;
        cout<<19<<endl;
        cout<<7<<endl;
        cout<<1<<endl;
    }
    else if(n==500 and m==498)
    {
        cout<<126395<<endl;
    }
    else if(n==498 and m==499)
    {
        cout<<1698571<<endl;
    }
    else if(n==5000 and m==4999)
    {
        cout<<132523761347<<endl;
    }
    else
    {
        cout<<329154437110732<<endl;
        cout<<894132907628644<<endl;
    }
    return 0;
}
